<template>
  <view class="policySettingMain">
    <view class="policySettingBox">
      <view class="policySettingOne">
        <u-cell-item
          icon="account-fill"
          title="代理商"
          :value="renderData.agentValue"
          :title-style="titleStyle"
          :value-style="valueStyle"
          @click="angentShowTap"
        ></u-cell-item>
        <u-cell-item
          icon="bookmark-fill"
          title="产品名称"
          :value="renderData.productValue"
          :title-style="titleStyle"
          :value-style="valueStyle"
          @click="productShowTap"
        ></u-cell-item>
      </view>
      <!-- <view class="tip">该代理商已设置政策，请不要重复设置</view> -->
      <u-sticky>
        <view class="tabBox">
          <u-tabs
            :list="tabList"
            :is-scroll="false"
            :current="current"
            @change="tabChange"
            active-color="#fb4535"
            font-size="28"
          ></u-tabs>
        </view>
      </u-sticky>
      <view class="policySettingTwo">
        <view class="title flex align-center" v-show="current == 0">
          <u-icon
            class="uIcon"
            name="setting-fill"
            color="#fb4535"
            size="48"
          ></u-icon>
          费率设置
        </view>
        <view class="twoBox" v-show="current == 0">
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>贷记卡</view>
              <text>{{ renderData.dataProduct.ccpay }}%</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.ccpay_min + '~' + renderData.dataProduct.ccpay_max"
                v-model="queryData.ccpay"
                @blur="inputBlur('ccpay', renderData.dataProduct.ccpay_max, renderData.dataProduct.ccpay_min )"
                :focus="state.ccpay"
                maxlength="5"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('ccpay')"
              ></u-icon>
            </view>
          </view>
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>借记卡</view>
              <text>{{ renderData.dataProduct.dcpay }}%</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.dcpay_min + '~' + renderData.dataProduct.dcpay_max"
                v-model="queryData.dcpay"
                @blur="inputBlur('dcpay', renderData.dataProduct.dcpay_max, renderData.dataProduct.dcpay_min)"
                :focus="state.dcpay"
                maxlength="5"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('dcpay')"
              ></u-icon>
            </view>
          </view>
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>银联扫码</view>
              <text>{{ renderData.dataProduct.cuppay }}%</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.cuppay_min + '~' + renderData.dataProduct.cuppay_max"
                v-model="queryData.cuppay"
                @blur="inputBlur('cuppay', renderData.dataProduct.cuppay_max, renderData.dataProduct.cuppay_min)"
                :focus="state.cuppay"
                maxlength="5"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('cuppay')"
              ></u-icon>
            </view>
          </view>
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>支付宝</view>
              <text>{{ renderData.dataProduct.alipay }}%</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.alipay_min + '~' + renderData.dataProduct.alipay_max"
                v-model="queryData.alipay"
                @blur="inputBlur('alipay', renderData.dataProduct.alipay_max, renderData.dataProduct.alipay_min)"
                :focus="state.alipay"
                maxlength="5"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('alipay')"
              ></u-icon>
            </view>
          </view>
          <view class="formItem flex align-center justify-between">
            <view class="left flex align-center">
              <view>微信支付</view>
              <text>{{ renderData.dataProduct.wxpay }}%</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.wxpay_min + '~' + renderData.dataProduct.wxpay_max"
                v-model="queryData.wxpay"
                @blur="inputBlur('wxpay', renderData.dataProduct.wxpay_max, renderData.dataProduct.wxpay_min)"
                :focus="state.wxpay"
                maxlength="5"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('wxpay')"
              ></u-icon>
            </view>
          </view>
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>借记卡封顶费</view>
              <text>{{ renderData.dataProduct.dctop }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.dctop_min + '~' + renderData.dataProduct.dctop_max"
                v-model="queryData.dctop"
                @blur="inputBlur('dctop', renderData.dataProduct.dctop_max, renderData.dataProduct.dctop_min)"
                :focus="state.dctop"
                :maxlength="queryData.dctop >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('dctop')"
              ></u-icon>
            </view>
          </view>
        </view>
        <view class="title flex align-center" v-show="current == 0">
          <u-icon
            class="uIcon"
            name="rmb-circle-fill"
            color="#fb4535"
            size="48"
          ></u-icon>
          提现设置
        </view>
        <view
          class="twoBox"
          v-show="current == 0"
          style="margin-bottom: 100rpx"
        >
          <view class="formItem flex align-center justify-between">
            <view class="left flex align-center">
              <view>T0手续费</view>
              <text>{{ renderData.dataProduct.t0 }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.t0_min + '~' + renderData.dataProduct.t0_max"
                v-model="queryData.t0"
                @blur="inputBlur('t0', renderData.dataProduct.t0_max, renderData.dataProduct.t0_min)"
                :focus="state.t0"
                :maxlength="queryData.t0 >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('t0')"
              ></u-icon>
            </view>
          </view>
        </view>
        <view class="title flex align-center" v-show="current == 1">
          <u-icon
            class="uIcon"
            name="red-packet-fill"
            color="#fb4535"
            size="44"
          ></u-icon>
          返现设置
        </view>
        <view class="twoBox" v-show="current == 1">
          <view class="formItem solid-bottom flex align-center justify-between">
            <view class="left flex align-center">
              <view>激活返现</view>
              <text>{{ renderData.dataProduct.active_reward }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.active_reward_min + '~' + renderData.dataProduct.active_reward_max"
                v-model="queryData.active_reward"
                @blur="
                  inputBlur(
                    'active_reward',
                    renderData.dataProduct.active_reward_max,
                    renderData.dataProduct.active_reward_min
                  )
                "
                :focus="state.active_reward"
                :maxlength="queryData.active_reward >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('active_reward')"
              >
              </u-icon>
            </view>
          </view>
          <view
            class="formItem solid-bottom flex align-center justify-between"
            v-if="renderData.dataProduct.standard_fee_1"
          >
            <view class="left flex align-center">
              <view
                >达标返现1<u-icon
                  class="uIcon"
                  name="question-circle"
                  color="#ccc"
                  size="32"
                  @click="
                    showQustion(
                      '达标返现1条件',
                      renderData.dataProduct.standard_fee_1_remard
                    )
                  "
                >
                </u-icon>
              </view>
              <text>{{ renderData.dataProduct.standard_fee_1 }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="'0~' + renderData.dataProduct.standard_fee_1"
                v-model="queryData.standard_fee_1"
                @blur="
                  inputBlur(
                    'standard_fee_1',
                    renderData.dataProduct.standard_fee_1,
                    0
                  )
                "
                :focus="state.standard_fee_1"
                :maxlength="queryData.standard_fee_1 >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('standard_fee_1')"
              >
              </u-icon>
            </view>
          </view>
          <view
            class="formItem flex align-center justify-between"
            v-if="renderData.dataProduct.standard_fee_2"
          >
            <view class="left flex align-center">
              <view
                >达标返现2<u-icon
                  class="uIcon"
                  name="question-circle"
                  color="#ccc"
                  size="32"
                  @click="
                    showQustion(
                      '达标返现2条件',
                      renderData.dataProduct.standard_fee_2_remard
                    )
                  "
                >
                </u-icon>
              </view>
              <text>{{ renderData.dataProduct.standard_fee_2 }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="'0~' + renderData.dataProduct.standard_fee_2"
                v-model="queryData.standard_fee_2"
                @blur="
                  inputBlur(
                    'standard_fee_2',
                    renderData.dataProduct.standard_fee_2,
                    0
                  )
                "
                :focus="state.standard_fee_2"
                :maxlength="queryData.standard_fee_2 >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('standard_fee_2')"
              >
              </u-icon>
            </view>
          </view>
        </view>
        <view class="title flex align-center" v-show="current == 2">
          <u-icon
            class="uIcon"
            name="bookmark-fill"
            color="#fb4535"
            size="44"
          ></u-icon>
          流量卡设置
        </view>
        <view class="twoBox" v-show="current == 2">
          <view class="formItem flex align-center justify-between">
            <view class="left flex align-center">
              <view>流量卡返现</view>
              <text>{{ renderData.dataProduct.service_data_fee }}元</text>
            </view>
            <view class="right flex align-center">
              <input
                type="digit"
                :placeholder="renderData.dataProduct.service_data_fee_min + '~' + renderData.dataProduct.service_data_fee_max"
                v-model="queryData.service_data_fee"
                @blur="
                  inputBlur(
                    'service_data_fee',
                    renderData.dataProduct.service_data_fee_max,
                    renderData.dataProduct.service_data_fee_min,
                  )
                "
                :focus="state.service_data_fee"
                :maxlength="queryData.service_data_fee >= 10 ? 5 : 4"
              />
              <u-icon
                name="edit-pen-fill"
                color="#fb4535"
                size="32"
                @click="inputTap('service_data_fee')"
              ></u-icon>
            </view>
          </view>
        </view>
        <view class="oButtonBox">
          <button
            type="default"
            @click="nextStepTap(1)"
            v-show="current == 0"
            :disabled="canNext"
          >
            下一步
          </button>
          <button
            type="default"
            @click="nextStepTap(2)"
            v-show="current == 1"
            :disabled="canNext"
          >
            下一步
          </button>
          <button type="default" @click="submitRateTap" v-show="current == 2">
            完成设置
          </button>
        </view>
      </view>
    </view>
    <!-- 代理商 -->
    <u-popup
      v-model="agentShow"
      mode="bottom"
      height="80%"
      :mask-close-able="false"
    >
      <view class="agentViewMain">
        <view class="agentViewHeader solid-bottom">
          <view
            class="backView flex align-center justify-center"
            @click="angentHideTap"
          >
            <u-icon name="arrow-left" color="#333" size="32"></u-icon>
          </view>
          <text>请选择代理商</text>
        </view>
        <view class="agentViewSearch solid-bottom">
          <u-search
            placeholder="请输入手机号或代理商姓名"
            v-model="searchAgent"
            :show-action="false"
            shape="square"
            @change="searchTap('searchAgent')"
          ></u-search>
          <text
            style="
              color: #f33;
              display: block;
              line-height: 80rpx;
              font-weight: bold;
            "
            >仅展示已实名代理商</text
          >
        </view>
        <view class="agentViewBox" v-if="renderData.agentList.length > 0">
          <view
            class="agentViewItem solid-bottom flex align-center justify-between"
            v-for="(item, index) in renderData.agentList"
            :key="index"
            @click="selectAgentTap(item, index)"
          >
            <view>{{item.nick_name}}-{{ item.account }}</view>
            <view
              class="radioView"
              :class="currentAgent == index ? 'active' : ''"
            ></view>
          </view>
        </view>
        <view
          class="noMachine flex align-center"
          style="padding-top: 300rpx"
          v-else
        >
          <image
            src="../../static/images/noData/zwsh.png"
            mode="widthFix"
          ></image>
          <text>暂无代理商</text>
        </view>
        <view class="agentBtnView"
          ><button style="width: 100%" type="default" @click="angentHideTap">
            确定
          </button>
        </view>
      </view>
    </u-popup>
    <!-- 产品 -->
    <u-popup
      v-model="productShow"
      mode="bottom"
      height="50%"
      :mask-close-able="false"
    >
      <view class="productViewMain">
        <view class="productViewHeader solid-bottom">
          <view
            class="backView flex align-center justify-center"
            @click="productHideTap"
          >
            <u-icon name="arrow-left" color="#333" size="32"></u-icon>
          </view>
          <text>请选择产品</text>
          <view class="comfirmView" @click="productHideTap">完成</view>
        </view>
        <view class="productViewBox" v-if="renderData.productsList.length > 0">
          <view
            class="
              productViewItem
              solid-bottom
              flex
              align-center
              justify-between
            "
            v-for="(item, index) in renderData.productsList"
            :key="index"
            @click="selectProductTap(item, index)"
          >
            <view>{{ item.name }}</view>
            <view
              class="radioView"
              :class="currentProduct == index ? 'active' : ''"
            ></view>
            <!-- <view class="radioView" :class="currentProduct == index ? 'active' : ''"
							v-if="item.user_product_id == '0'"></view> 
						<view class="settingStatus" v-else>已设置</view> -->
          </view>
        </view>
        <view class="noMachine flex align-center" v-else style="padding-top: 0">
          <image
            src="../../static/images/noData/zwsh.png"
            mode="widthFix"
          ></image>
          <text>暂无产品</text>
        </view>
      </view>
    </u-popup>
    <u-modal
      v-model="show"
      :content="content"
      show-cancel-button
      @confirm="confirm"
      @cancel="cancel"
      confirm-color="#fb4535"
    ></u-modal>
    <u-modal
      v-model="qustionShow"
      :content="qustionContent"
      :title="qustionTitle"
      confirm-color="#fb4535"
    >
    </u-modal>

    <!-- 通知弹窗 -->
    <u-modal
      v-model="remindShow"
      :content="remindContent"
      @confirm="remindConfirm"
      :mask-close-able="true"
      confirm-color="#fb4535"
    ></u-modal>
    <u-toast ref="uToast" />
    <toast></toast>
  </view>
</template>

<script>
export default {
  data() {
    return {
      titleStyle: {
        color: "#333333",
        fontSize: "32rpx",
      },
      valueStyle: {
        color: "#666666",
        fontSize: "32rpx",
      },
      currentAgent: -1,
      searchAgent: "",
      searchAgentParams: "",
      currentProduct: -1,
      nuserId: "",
      productId: "",
      renderData: {
        agentValue: "请选择代理商",
        productValue: "请选择产品",
        agentList: [],
        productsList: [],
        dataProduct: {
          ccpay: "0.00",
          ccpay_min: "0.00",
          ccpay_max: "0.00",
          dcpay: "0.00",
          dcpay_min: "0.00",
          dcpay_max: "0.00",
          cuppay: "0.00",
          cuppay_min: "0.00",
          cuppay_max: "0.00",
          alipay: "0.00",
          alipay_min: "0.00",
          alipay_max: "0.00",
          wxpay: "0.00",
          wxpay_max: "0.00",
          wxpay_min: "0.00",
          dctop: "0.00",
          dctop_min: "0.00",
          dctop_max: "0.00",
          t0: "0.00",
          t0_min: "0.00",
          t0_max: "0.00",
          active_reward: "0.00",
          active_reward_min: "0.00",
          active_reward_max: "0.00",
          service_data_fee: "0.00",
          service_data_fee_min: "0.00",
          service_data_fee_max: "0.00",
          standard_fee_1: "",
          standard_fee_2: "",
          standard_fee_3: "",
          standard_fee_1_remard: "",
          standard_fee_2_remard: "",
          standard_fee_3_remard: "",
          agent_code: "",
          machine_count: "0",
          name: "",
          product_id: "",
          user_product_id: 0,
        },
      },
      agentShow: false,
      productShow: false,
      queryData: {
        dcpay: "",
        dctop: "",
        ccpay: "",
        cuppay: "",
        alipay: "",
        wxpay: "",
        t0: "",
        active_reward: "",
        service_data_fee: "",
        standard_fee_1: "",
        standard_fee_2: "",
        standard_fee_3: "",
      },
      state: {
        dcpay: false,
        dctop: false,
        ccpay: false,
        cuppay: false,
        alipay: false,
        wxpay: false,
        t0:false,
        active_reward: false,
        service_data_fee: false,
        standard_fee_1: false,
        standard_fee_2: false,
        standard_fee_3: false,
      },
      tabList: [
        {
          name: "费率设置",
        },
        {
          name: "返现设置",
        },
        {
          name: "流量卡设置",
        },
      ],
      current: 0,
      show: false,
      content: "确认当前设置吗？",
      qustionShow: false,
      qustionTitle: "",
      qustionContent: "",
      canNext: false,

      // 通知弹窗
      remindShow: true,
      remindContent: "若有存量的合作方   请核对配置的政策",
    };
  },
  onLoad() {
    this.getGetTransferUsers();
    // 通知弹窗时限
    let timestamp = Date.parse(new Date());
    if (timestamp > 1630425599000) {
      this.remindShow = false;
    }
  },
  methods: {
    tabChange(index) {
      if (this.nuserId == "") {
        this.$refs.uToast.show({
          title: "请选择代理商",
          type: "error",
          duration: "1500",
        });
        return;
      }
      if (this.productId == "") {
        this.$refs.uToast.show({
          title: "请选择产品",
          type: "error",
          duration: "1500",
        });
        return;
      }
      this.current = index;
    },
    nextStepTap(index) {
      if (this.nuserId == "") {
        this.$refs.uToast.show({
          title: "请选择代理商",
          type: "error",
          duration: "1500",
        });
        return;
      }
      if (this.productId == "") {
        this.$refs.uToast.show({
          title: "请选择产品",
          type: "error",
          duration: "1500",
        });
        return;
      }
      this.current = index;
    },
    angentShowTap() {
      this.agentShow = true;
      this.currentAgent = -1;
      this.searchAgentParams = "";
      this.searchAgent = "";
      this.productId = "";
      this.renderData.productValue = "请选择产品";
      this.getGetTransferUsers();
    },
    angentHideTap() {
      this.agentShow = false;
    },
    productShowTap() {
      if (this.renderData.agentValue == "请选择代理商") {
        this.$refs.uToast.show({
          title: "请选择代理商",
          type: "error",
          duration: "1500",
        });
        return;
      }
      this.productShow = true;
    },
    productHideTap() {
      this.productShow = false;
      this.current = 0;
    },
    //获取代理列表
    getGetTransferUsers() {
      this.$u.api
        .userZcList({
          auth_status: 2,
          key_words: this.searchAgentParams,
        })
        .then((res) => {
          if (res.status == 200) {
            let datas = res.result.list;
            datas = this.$tools.aesDecryptBat(this, datas, "account");
            this.renderData.agentList = datas;
          }
        })
        .catch((res) => {
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
             this.$u.toast("请求失败，请重试");
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },
    //获取获取调拨代理对应的产品列表
    getTransferProducts(agentId) {
      this.nuserId = agentId;
      this.$u.api
        .productlist({
          all: "2",
          user_id: agentId,
        })
        .then((res) => {
          if (res.status == 200) {
            let datas = res.result.list;
            this.renderData.productsList = datas;
          }
        })
        .catch((res) => {
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
             this.$u.toast("请求失败，请重试");
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },
    searchTap() {
      this.currentAgent = -1;
      this.searchAgentParams = this.searchAgent;
      this.getGetTransferUsers();
      // let reg = /^[0-9]+.?[0-9]*$/;
      // let searchAgent = this.searchAgent;
      // if (reg.test(searchAgent)) {
      //   this.searchAgentParams = this.$tools.aesEncrypt(this, searchAgent);
      //   this.getGetTransferUsers();
      // } else {
      //   this.searchAgentParams = this.searchAgent;
      //   this.getGetTransferUsers();
      // }
    },
    //选择类
    selectAgentTap(item, index) {
      this.currentAgent = index;
      this.renderData.agentValue = `${item.real_name}-${item.account}`;
      this.getTransferProducts(item.user_id);
      this.currentProduct = -1;
      this.current = 0;
    },
    selectProductTap(item, index) {
      this.currentProduct = index;
      this.renderData.productValue = item.name;
      this.renderData.dataProduct = item;
      this.productId = item.product_id;
      this.user_product_id = item.user_product_id;
      // if (item.user_product_id == 0) {
      // 	this.currentProduct = index;
      // 	this.renderData.productValue = item.name;
      // 	this.renderData.dataProduct = item;
      // 	this.productId = item.product_id;
      // } else {
      // 	this.$refs.uToast.show({
      // 		title: "该产品已设置",
      // 		type: "error",
      // 	});
      // }
    },
    inputBlur(type, maxNum, minNum) {
      // console.log(`type:${type},最大值：${maxNum},最小值：${minNum}`)
      this.state[type] = false;
      if (this.nuserId == "") {
        this.$refs.uToast.show({
          title: "请选择代理商",
          type: "error",
          duration: "1500",
        });
        return;
      }
      if (this.productId == "") {
        this.$refs.uToast.show({
          title: "请选择产品",
          type: "error",
          duration: "1500",
        });
        return;
      }
      if (this.queryData[type] != "") {
        if (this.queryData[type] < 0 || this.queryData[type] == "-0") {
          this.$refs.uToast.show({
            title: "不能为负值",
            type: "error",
          });
          this.queryData[type] = "";
          return;
        }
        // 比较
        if (
          parseFloat(this.queryData[type]) > parseFloat(maxNum)
        ) {
          this.$refs.uToast.show({
            title: "不能高于" + `${maxNum}`,
            type: "error",
          });
          this.canNext = true;
          setTimeout(() => {
            this.canNext = false;
          }, 1000);
          this.queryData[type] = "";
        } else if (
          parseFloat(this.queryData[type]) < parseFloat(minNum) 
        ) {
          this.$refs.uToast.show({
            title: `不能低于${minNum}`,
            type: "error",
          });
          this.canNext = true;
          setTimeout(() => {
            this.canNext = false;
          }, 1000);
          this.queryData[type] = "";
        } 
      }
    },
    inputTap(type) {
      this.state[type] = true;
    },
    //政策设定提交
    submitRateTap() {
      if (this.nuserId == "") {
        this.$refs.uToast.show({
          title: "请选择代理商",
          type: "error",
          duration: "1500",
        });
        return;
      }
      if (this.productId == "") {
        this.$refs.uToast.show({
          title: "请选择产品",
          type: "error",
          duration: "1500",
        });
        return;
      }
      this.show = true;
    },

    confirm() {
      let user_product_id = this.user_product_id;
      let params = {};
      if (user_product_id == "0") {
        //未设置
        params = {
          product_id: this.productId,
          user_id: this.nuserId,
          dcpay: this.queryData.dcpay
            ? this.queryData.dcpay
            : this.renderData.dataProduct.dcpay,
          dctop: this.queryData.dctop
            ? this.queryData.dctop
            : this.renderData.dataProduct.dctop,
          ccpay: this.queryData.ccpay
            ? this.queryData.ccpay
            : this.renderData.dataProduct.ccpay,
          cuppay: this.queryData.cuppay
            ? this.queryData.cuppay
            : this.renderData.dataProduct.cuppay,
          alipay: this.queryData.alipay
            ? this.queryData.alipay
            : this.renderData.dataProduct.alipay,
          wxpay: this.queryData.wxpay
            ? this.queryData.wxpay
            : this.renderData.dataProduct.wxpay,
          t0: this.queryData.t0
            ? this.queryData.t0
            : this.renderData.dataProduct.t0,
          active_reward: this.queryData.active_reward
            ? this.queryData.active_reward
            : this.renderData.dataProduct.active_reward,
          service_data_fee: this.queryData.service_data_fee
            ? this.queryData.service_data_fee
            : this.renderData.dataProduct.service_data_fee,
          standard_fee_1: this.queryData.standard_fee_1
            ? this.queryData.standard_fee_1
            : this.renderData.dataProduct.standard_fee_1,
          standard_fee_2: this.queryData.standard_fee_2
            ? this.queryData.standard_fee_2
            : this.renderData.dataProduct.standard_fee_2,
        };
      } else {
        //已设置
        params = {
          product_id: this.productId,
          user_id: this.nuserId,
          dcpay: this.renderData.dataProduct.dcpay,
          dctop: this.renderData.dataProduct.dctop,
          ccpay: this.renderData.dataProduct.ccpay,
          cuppay: this.renderData.dataProduct.cuppay,
          alipay: this.renderData.dataProduct.alipay,
          wxpay: this.renderData.dataProduct.wxpay,
          t0: this.renderData.dataProduct.t0,
          active_reward: this.queryData.active_reward
            ? this.queryData.active_reward
            : this.renderData.dataProduct.active_reward,
          service_data_fee: this.queryData.service_data_fee
            ? this.queryData.service_data_fee
            : this.renderData.dataProduct.service_data_fee,
          standard_fee_1: this.queryData.standard_fee_1
            ? this.queryData.standard_fee_1
            : this.renderData.dataProduct.standard_fee_1,
          standard_fee_2: this.queryData.standard_fee_2
            ? this.queryData.standard_fee_2
            : this.renderData.dataProduct.standard_fee_2,
        };
      }
      let that = this;
      that.$u.api
        .userProductSetting(params)
        .then((res) => {
          if (res.status == 200) {
            that.$refs.uToast.show({
              title: res.result,
              type: "success",
            });
            setTimeout(() => {
              that.$u.route({
                url: "/pages/myTeam/myTeam",
                type: "redirect",
              });
            }, 2000);
          } else {
            that.$refs.uToast.show({
              title: res.msg,
              type: "error",
              duration: "2000",
            });
          }
        })
        .catch((res) => {
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
             this.$u.toast("请求失败，请重试");
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },

    cancel() {
      this.show = false;
    },
    showQustion(title, content) {
      this.qustionShow = true;
      this.qustionTitle = title;
      this.qustionContent = content;
    },

    remindConfirm() {
      this.remindShow = false;
    },
  },
};
</script>

<style lang="scss">
.policySettingBox {
  .policySettingOne {
    background-color: #fff;
  }

  .tip {
    line-height: 80rpx;
    color: #f33;
    font-size: 28rpx;
    padding: 0 32rpx;
  }

  .policySettingTwo {
    padding: 30rpx 32rpx 50rpx;

    .title {
      height: 100rpx;
      font-size: 36rpx;
      color: $uni-text-color;

      .uIcon {
        margin-right: 10rpx;
      }
    }

    .twoBox {
      background-color: #fff;
      border-radius: 10rpx;
      padding: 0 20rpx;
      margin-bottom: 30rpx;

      .formItem {
        height: 100rpx;
        padding: 0 20rpx;

        .left {
          > view {
            width: 200rpx;
            position: relative;
            top: -2rpx;
            font-size: 32rpx;
            color: $uni-text-color;
            margin-right: 30rpx;

            .uIcon {
              margin-left: 10rpx;
              position: relative;
              top: 1rpx;
            }
          }

          > text {
            display: block;
            font-size: 32rpx;
            color: $uni-text-color;
            margin-right: 30rpx;
            position: relative;
          }
        }

        .right {
          width: 35%;
          position: relative;
          top: 2rpx;
          text-align:right;
          input{
            margin-right:16rpx;
          }
          > text {
            font-size: 36rpx;
            color: #fb4535;
            font-weight: bold;
          }
        }
      }
    }

    > .oButtonBox {
      position: fixed;
      left: 0;
      bottom: 0;
      padding: 30rpx;
      width: 100%;
      box-sizing: border-box;

      > button {
        background-color: #fb4535;
        font-size: 32rpx;
        color: #fff;
        width: 100%;

        &::after {
          border: none;
        }
      }
    }
  }
}

.agentViewMain {
  position: relative;

  .agentViewHeader {
    height: 80rpx;
    text-align: center;
    line-height: 80rpx;
    font-size: 32rpx;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    background-color: #fff;
    z-index: 9;

    .backView {
      width: 80rpx;
      height: 80rpx;
      position: absolute;
      left: 0;
      top: 0;
    }
  }

  .agentViewSearch {
    padding: 20rpx 30rpx 0;
    box-sizing: border-box;
    position: fixed;
    width: 100%;
    left: 0;
    top: 80rpx;
    background-color: #fff;
    z-index: 9;
  }

  .agentViewBox {
    padding: 244rpx 30rpx 120rpx;

    .agentViewItem {
      height: 100rpx;
    }
  }

  .agentBtnView {
    padding: 20rpx 30rpx;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    background-color: #fff;

    > button {
      background-color: #fb4535;
      font-size: 32rpx;
      color: #fff;

      &::after {
        border: none;
      }
    }
  }
}

.productViewMain {
  position: relative;

  .productViewHeader {
    height: 80rpx;
    text-align: center;
    line-height: 80rpx;
    font-size: 32rpx;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    background-color: #fff;
    z-index: 9;

    .backView {
      width: 80rpx;
      height: 80rpx;
      position: absolute;
      left: 0;
      top: 0;
    }

    .comfirmView {
      height: 80rpx;
      line-height: 80rpx;
      font-size: 28rpx;
      color: #fb4535;
      padding: 0 30rpx;
      position: absolute;
      right: 0;
      top: 0;
    }
  }

  .productViewBox {
    padding: 80rpx 30rpx 0;

    .productViewItem {
      height: 100rpx;
    }
  }
}

.settingStatus {
  font-weight: bold;
  color: #f33;
}

.radioView {
  width: 40rpx;
  height: 40rpx;
  border-radius: 50%;
  border: 2rpx solid #ccc;

  &.active {
    border-color: #fb4535;
    background-color: #fb4535;
    position: relative;

    &::before {
      content: "";
      display: block;
      width: 10rpx;
      height: 6rpx;
      background-color: #fff;
      transform: rotate(45deg);
      position: absolute;
      left: 6rpx;
      top: 18rpx;
    }

    &::after {
      content: "";
      display: block;
      width: 22rpx;
      height: 6rpx;
      background-color: #fff;
      transform: rotate(-45deg);
      position: absolute;
      left: 10rpx;
      top: 16rpx;
    }
  }
}
</style>
